﻿<#

.SYNOPSIS
Renames current PC.

.DESCRIPTION
If RestartOnCompletion is provided and set to true, 
then the machine will restart after completion.

.EXAMPLE
Rename-Computer -NewComputerName "VM-SP-WFE" -RestartOnCompletion true

.LINK
http://usefulPOSHCmdlets.codeplex.com

#>
function Rename-Computer(
	[Parameter(Mandatory=$True, Position=0)]
    [string]$NewComputerName,
	
	[Parameter(Mandatory=$false, Position=1)]
	[bool]$RestartOnCompletion
	) {
	$computer = Get-WmiObject -Class Win32_ComputerSystem
	
	$result = $computer.Rename($NewComputerName)

	Write-Host "Computer renamed to: $result"
	
	if ($RestartOnCompletion){
		Restart-Computer
	}
}


<#

.SYNOPSIS
Disables Internet Explorer Enhanced Security.

.DESCRIPTION
Both Admin and User will be disabled unless parameters
are provided

.EXAMPLE
Disable-IEESC

.EXAMPLE
Disable-IEESC -DisableAdmin false -DisableUser false

.LINK
http://usefulPOSHCmdlets.codeplex.com

#>
function Disable-IEESC (
	[Parameter(Mandatory=$false, Position=0)]
    [bool]$DisableAdmin=$True,
	
	[Parameter(Mandatory=$false, Position=1)]
	[bool]$DisableUser=$True
	){
	$adminKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
	$userKey = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"

	if ($DisableAdmin) {
		Set-ItemProperty -Path $adminKey -Name "IsInstalled" -Value 0
	}

	if ($DisableUser) {
		Set-ItemProperty -Path $userKey -Name "IsInstalled" -Value 0
	}

	Stop-Process -Name Explorer
}


<#

.SYNOPSIS
Changes PC Time Zone.

.DESCRIPTION
Changes Time Zone using tzutil executable.

.EXAMPLE
Rename-Computer -NewComputerName "VM-SP-WFE" -RestartOnCompletion true

.LINK
http://usefulPOSHCmdlets.codeplex.com

#>
function Set-TimeZone(
	[Parameter(Mandatory=$True, Position=0)]
	[string]$TimeZoneName
) {
	
	C:\Windows\System32\tzutil.exe /s $TimeZoneName
}



<#

.SYNOPSIS
Creates CS files given config file list.

.DESCRIPTION
Generates CS files with inline code.  Useful for mass
class creation where classes have similar code base.

.EXAMPLE
Create-CodeFiles -Path "C:\SourceCode\SharePoint\BigProject\SiteColumns" -ConfigFile "SiteColumnClassList.txt"

.LINK
http://usefulPOSHCmdlets.codeplex.com

#>

function Create-CodeFiles (
	[Parameter(Mandatory=$True, Position=0)]
	[string]$Path,
	[Parameter(Mandatory=$True, Position=1)]
	[string]$ConfigFile
){

#Moves to file path
cd $Path

$fileNames = Get-Content $ConfigFile

	foreach ($line in $fileNames){
		#gets file if it exists
		$existingFile = @(Get-ChildItem | Where-Object{
			$_.Name -eq "$line.cs"
		})

		#if file doesn't exist, create it
		if($existingFile.Length -eq 0){
			$fileName = $line

			$fileContents = @"
using System.Net;
using Microsoft.SharePoint;

namespace SPSamL.Examples
{
   public class $fileName
   {
      public $fileName()
	  {
	     //BoilerPlate code for $fileName
	  }
   }
}
"@
			New-Item "$fileName.cs" -type file -value $fileContents
		}
	}
}
